package com.ucap.bbs.util.template;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import com.ucap.bbs.controller.filter.DefaultFilter;

public class BaseTemplate {
    public BaseTemplate() {
       
        try{
            List<String> list = new ArrayList<String>();
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
            list.add("aa");
            list.add("bb");
            list.add("cc");
          //  request.setAttribute("listBeans", list);
        File saveDir = new  File(DefaultFilter.getRealPath()+"html");  
        //静态文件存放目录  
        if(!saveDir.exists())saveDir.mkdirs();  
        VelocityContext context = new VelocityContext();  
        context.put("list", list);//将数据放到velocity内容对象内  
        context.put("name", "张三");
        Template template = Velocity.getTemplate("index.htm");  
        //获得模版; 注意,是在properties里面已经配好的模版目录下  
        FileOutputStream outStream = new FileOutputStream(new File(saveDir,"index.html"));//生成静态文件名为index.html  
        OutputStreamWriter writer = new OutputStreamWriter(outStream,"UTF-8");           
        BufferedWriter sw = new BufferedWriter(writer);  
        template.merge(context, sw);  
        sw.flush();  
        sw.close();  
        outStream.close();  
        }  
        catch(Exception e)  
        {  
            e.printStackTrace();  
        }  
    }
}
